<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-content">
                <form class="form-horizontal m-t" id="signupForm">
                    <div class="row">
                        <div class="col-md-6 pd-10 form-item">
                            <div class="input-group">
                                <input type="hidden" name="id" id="id" th:value="${entity.id}"/>
                            </div>
                        </div>
                       <div class="col-md-6 pd-10 form-item">
                           <div class="input-group">
                               <span class="input-group-addon">姓名：</span>
                               <input id="name" name="name" class="form-control" type="text" th:value="${entity.name}">
                           </div>
                       </div>
                       <div class="col-md-6 pd-10 form-item">
                           <div class="input-group">
                               <span class="input-group-addon">年龄：</span>
                               <input id="age" name="age" class="form-control" type="text" th:value="${entity.age}">
                           </div>
                       </div>
                        <div class="col-md-6 pd-10 form-item">
                            <div class="input-group">
                                <span class="input-group-addon">生日：</span>
                                <input id="birth" name="birth" class="form-control" type="text"
                                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                       th:value="${#dates.format(entity.birth, 'yyyy-MM-dd HH:mm:ss')}">
                            </div>
                        </div>
                        <div class="col-md-6 pd-10 form-item">
                            <div class="input-group">
                                <span class="input-group-addon">创建时间：</span>
                                <input id="createTime" name="createTime" class="form-control" type="text"
                                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                       th:value="${entity.createTime}">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-8 col-sm-offset-3">
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script th:utext="'var pageMode = \''+${pageMode}+'\', excludeFields = '+${excludeFields}+';'"></script>
<script type="text/javascript">
  $().ready(function () {
    // 禁用掉剔除掉的字段
    $(excludeFields).each(function(idx, field){
      var obj = document.getElementById(field);
      if(obj) obj.disabled = true;
      $(obj).parents('.form-item').hide();
      if(pageMode == 'unique') {
          $('.submit').text('返回')
          save = function() {
              var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
              parent.layer.close(index);
          }
      }
    });
    window[pageMode+'Page']();
    validateRule();
  });

  $.validator.setDefaults({
    submitHandler: function () {
      save();
    }
  });

  function updatePage() {
      $('#id').parents('.form-item').hide();
  }
  function uniquePage() {
      $('.form-control').each(function(idx, obj) {
          if(obj) obj.disabled = true;
      })
  }
  function savePage() {

  }

  function save() {
    $.ajax({
      cache: true,
      type: "POST",
      url: "/system/student/" + pageMode,
      data: $('#signupForm').serialize(excludeFields),// 你的formid
      async: false,
      error: function (request) {
        parent.layer.alert("Connection error");
      },
      success: function (data) {
        if (data.code == 0) {
          parent.layer.msg("操作成功");
          parent.reLoad();
          var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
          parent.layer.close(index);

        } else {
          parent.layer.alert(data.msg)
        }

      }
    });

  }

  function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
      rules: {
        name: {
          required: true
        }
      },
      messages: {
        name: {
          required: icon + "请输入姓名"
        }
      }
    })
  }
</script>
</body>
</html>
